<template>
	<div class="container ">
		<!-- <st-navigation title="社会公益"></st-navigation> -->
		<!-- <view class="empty-wrap"></view> -->
		<view class="public-welfare ysm-padding" v-for="(socialbenefits, index) of socialbenefitsList" :key="index">
			<view class="top-title">
				{{ socialbenefits.title }}
			</view>
			<view class="ysm-mt">
				<video id="myVideo" class="viedo" :src="socialbenefits.video"
					:poster-for-crawler="socialbenefits.video_img" enable-danmu danmu-btn controls></video>
			</view>

			<view :class="{ 'limited': socialbenefits.isLimited }" class="content">
				<view class="info">
					<template v-if="socialbenefits.isLimited">
						<view class="info-wrap">
							<text class="title">节目介绍：</text>
							<text>{{ socialbenefits.limitedContent }}</text>
							<text class="more" @click="toggleLimited(socialbenefits)">
								{{ socialbenefits.showAll ? '收起' : '更多>>' }} </text>
							<!-- <rich-text :nodes="socialbenefits.limitedContent"></rich-text> -->
						</view>
					</template>
					<template v-else>
						<view class="info-wrap">
							<text class="title">节目介绍：</text>
							<text>{{ socialbenefits.limitedContent }}</text>
							<!-- <rich-text :nodes="socialbenefits.limitedContent"></rich-text> -->
						</view>
					</template>

				</view>
			</view>
		</view>
		<!-- <view class="empty-wrap"></view> -->
	</div>
</template>

<script>
	export default {
		data() {
			return {
				socialbenefitsList: [],
				// socialbenefits:{},
				showAll: false,
				lineHeight: 20,
				limitedHeight: 20 * 3,
				limitedContent: '',
				content: '',
			}
		},
		computed: {
			isLimited() {
				return this.content.length * this.lineHeight > this.limitedHeight;
			},
		},
		methods: {
			// 获取 https://www.ysmll.cn/api/wanlshop/user/getSocialbenefits 社会公益
			getSocialbenefits() {
				
				this.$api.get({
					url: '/wanlshop/user/getSocialbenefits',
					success: res => {
						let socialbenefitsList = res.map(x => {
							return {
								...x,
								showAll: false,
								isLimited: x.content.length * this.lineHeight > this.limitedHeight,
								// limitedContent: x.content.substring(0,29)+'......'+ x.content.substring(x.content.length-10,x.content.length)
								limitedContent: x.content.substring(0, 40) + '...',
							}
						});
						this.socialbenefitsList = socialbenefitsList;
						
						// this.socialbenefits = res
						// this.content = res.content
						// this.limitedContent = this.content.substring(0,60)+'...';
					}
				})
			},
			toggleLimited(item) {
				item.showAll = !item.showAll;
				if (item.showAll) {
					item.limitedContent = item.content;
				} else {
					item.limitedContent = item.content.substring(0, 40) + '...';
				}
			},
		},
		created() {
			this.getSocialbenefits();
			console.log(this.isLimited)
		}
	}
</script>

<style scoped lang="less">
	.ysm-padding {
		padding: 32rpx;
	}

	.ysm-mt {
		margin-bottom: 32rpx;
	}

	.container {
		// background-color: #fff;
		height: 100%;
		padding-bottom: 40rpx;

		.empty-wrap {
			width: 100%;
			height: 16rpx;
			background: #F0F0F0;
		}

		.top-title {
			font-family: 'PingFang SC';
			font-style: normal;
			font-weight: 600;
			font-size: 32rpx;
			line-height: 53rpx;
			color: #333333;
			margin-bottom: 24rpx;
		}

		.viedo {
			width: 100%;
			height: 190px;
		}

		.content {
			position: relative;

			.info {
				position: relative;

				// 	word-break: break-all;
				// 	text-overflow: ellipsis;
				// //可以直接用以下4行的代码
				// 	display: -webkit-box;
				// 	overflow: hidden;
				// 	-webkit-box-orient: vertical;
				// 	-webkit-line-clamp: 3;
				.title {
					font-family: 'PingFang SC';
					font-style: normal;
					font-weight: 600;
					font-size: 32rpx;
					line-height: 53rpx;
					color: #333333;
				}

				.more {
					text-align: right;
					color: #1D76C6;
				}
			}
		}

	}

	.public-welfare {
		background: #fff;
		margin-top: 20rpx;
	}
</style>